package com.mogist.hqc.module.product.adapter

import android.view.View
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mogist.hqc.R
import com.mogist.hqc.entitys.response.MainProductVo
import talex.zsw.basecore.util.DimenTool
import talex.zsw.basecore.util.MathTool
import talex.zsw.basecore.util.RegTool
import talex.zsw.basecore.util.glide.GlideTool

/**
 * 作用：订单列表
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class Product0Adapter : BaseQuickAdapter<MainProductVo, BaseViewHolder>(R.layout.item_product_0)
{
    override fun convert(helper: BaseViewHolder, item: MainProductVo)
    { //iTvStart iImage iTvTitle iLLTag iTvTag1 iTvTag2 iTvTag3 iTvPrice
        helper.setText(R.id.iTvTitle, item.pdtName)
                .setText(R.id.iTvPrice, MathTool.roundStr(item.price, 2))
                .setText(R.id.iTvStart, "${item.basePlace}出发")
        if (RegTool.isNotEmpty(item.tags))
        {
            val strs =
                    item.tags.split("[;,/，、|]".toRegex())
                            .dropLastWhile { it.isEmpty() }
                            .toTypedArray()
            helper.getView<LinearLayout>(R.id.iLLTag)
                    .visibility = View.VISIBLE
            helper.setText(R.id.iTvTag1, strs[0])
            if (strs.size > 1)
            {
                helper.setText(R.id.iTvTag2, strs[1])
                        .setVisible(R.id.iTvTag2, true)
                if (strs.size > 2)
                {
                    helper.setText(R.id.iTvTag3, strs[2])
                            .setVisible(R.id.iTvTag3, true)
                }
                else
                {
                    helper.setVisible(R.id.iTvTag3, false)
                }
            }
            else
            {
                helper.setVisible(R.id.iTvTag2, false)
                        .setVisible(R.id.iTvTag3, false)
            }
        }
        else
        {
            helper.getView<LinearLayout>(R.id.iLLTag)
                    .visibility = View.GONE
        }

        GlideTool.loadImgRoundedCornersTop(helper.getView(R.id.iImage),
                                           item.pdtImg,
                                           DimenTool.dp2px(12f))
    }
}